home *** CD-ROM | disk | FTP | other *** search
- (* $VER: fio 1.2 (24-Nov-93) Copyright © by Lars Düning *)
-
- DEFINITION fio;
-
- ---------------------------------------------------------------------------
- File-IO for Amiga-Oberon.
-
- Copyright © 1991-1993 Lars Düning - All rights reserved.
- Permission granted for non-commercial use.
- ---------------------------------------------------------------------------
- CREDIT
- The module evolved from the io standard module of Amiga-Oberon 1.17.1
- ---------------------------------------------------------------------------
-
- CONST
-
- StdBufSize * = FSystem.StdBufSize; default buffer size
-
-
- CONST: Open() access modes
-
- newFile * = FSystem.newFile; excl. access, deletes existing file
- oldFile * = FSystem.oldFile; shared access, file has to exist
- update * = FSystem.update; excl. access, file may exist
-
-
- CONST: Open() operation modes
-
- writeOnly * = FSystem.writeOnly;
- readOnly * = FSystem.readOnly;
- readWrite * = FSystem.readWrite;
-
-
- CONST: File.status, in fact error codes
-
- ok * = FSystem.ok; no error
- eof * = FSystem.eof; reached end of file
- readerr * = FSystem.readerr; unspecified read error, ask Dos
- writeerr * = FSystem.writeerr; unspecified write error, ask Dos
- onlyread * = FSystem.onlyread; file is read only
- onlywrite * = FSystem.onlywrite; file is write only
- toofar * = FSystem.toofar; seeked beyond the file's ends
- outofmem * = FSystem.outofmem; ran out of memory
- cantopen * = FSystem.cantopen; couldn't open file
- cantlock * = FSystem.cantlock; couldn't lock file
-
-
- TYPE
-
- FilePtr * = FSystem.FilePtr;
- File * = FSystem.File;
-
-
- VAR: stdio of the process initializing the modules
-
- stdin * : Dos.FileHandlePtr; starting process's standard input
- stdout * : Dos.FileHandlePtr; starting process's standard outout
- stderr * : Dos.FileHandlePtr; starting process's standard error output
-
-
- PROCEDURE Use * (VAR file: File
- ; name: ARRAY OF CHAR
- ; accMode: INTEGER
- ; opMode : INTEGER
- ; bufsize: LONGINT
- ): BOOLEAN;
-
- Open a file according to access and operation mode.
-
- Arguments:
- file: the empty(!) File structure to fill in.
- name: the name of the file to open (will be copied into file).
- accMode: the access mode to use.
- opMode : the operation mode to use.
- bufSize: size of the buffer to allocate, must be at least 1.
-
- Result:
- TRUE on success, else FALSE with file.status denoting the error.
-
- A bufsize of 1 will result in unbuffered io.
-
-
- PROCEDURE open * (VAR file: File
- ; name: ARRAY OF CHAR
- ; accMode: INTEGER
- ): BOOLEAN;
-
- Open a file for read/write with a default sized buffer.
-
- Arguments:
- file: the empty(!) File structure to fill in.
- name: the name of the file to open (will be copied into file).
- accMode: the access mode to use.
-
- Result:
- TRUE on success, else FALSE with file.status denoting the error.
-
- The allocated buffer will be of StdBufSize.
- The file will be opened for reading and writing.
-
-
- PROCEDURE close * (VAR file: File);
- PROCEDURE Close * (VAR file: File): BOOLEAN;
-
- Close the file.
-
- Arguments:
- file: the file to close.
-
- Result:
- TRUE on success, else FALSE with file.status denoting the error.
-
- Before closing, all changed data is written out using FlushBuf().
-
-
- PROCEDURE StdIn * () : Dos.FileHandlePtr;
-
- The current processes standard input.
-
- Result:
- The FileHandle of standard input or NIL;
-
- Don't call this function for simple tasks!
-
-
- PROCEDURE StdOut * () : Dos.FileHandlePtr;
-
- The current processes standard output.
-
- Result:
- The FileHandle of standard output or NIL;
-
- Don't call this function for simple tasks!
-
-
- PROCEDURE StdErr * () : Dos.FileHandlePtr;
-
- The current processes standard error output.
-
- Result:
- The FileHandle of standard error output or NIL;
-
- Don't call this function for simple tasks!
- For OS < 2.0, stderr is stdout.
-
- PROCEDURE Length * (str: ARRAY OF CHAR): INTEGER;
-
- Determine the length of a string.
-
- Arguments:
- str: the string to check.
-
- Result:
- The strings length.
-
- The replication of this function here (it belongs to Strings) shows
- clearly the need for INLINE PROCEDUREs.
-
-
- PROCEDURE write * (VAR out : File; ch: CHAR);
- PROCEDURE Write * (VAR out : File; ch: CHAR) : BOOLEAN;
-
- Write a character into a file.
-
- Arguments:
- ch : the character to write.
- out: the file to write into.
-
- Result:
- TRUE on success, else FALSE with out.status denoting the error.
-
-
- PROCEDURE writeLn * (VAR out : File);
- PROCEDURE WriteLn * (VAR out : File) : BOOLEAN;
-
- Write a Newline into a file.
-
- Arguments:
- out: the file to write into.
-
- Result:
- TRUE on success, else FALSE with out.status denoting the error.
-
-
- PROCEDURE writeString * (VAR out: File; str: ARRAY OF CHAR);
- PROCEDURE WriteString * (VAR out: File; str: ARRAY OF CHAR) : BOOLEAN;
-
- Write a string into a file.
-
- Arguments:
- out: the file to write into.
- str: the string to write.
-
- Result:
- TRUE on success, else FALSE with out.status denoting the error.
-
- Newlines are not addeDos.
-
-
- PROCEDURE tab * (VAR out : File; n: INTEGER);
- PROCEDURE Tab * (VAR out : File; n: INTEGER) : BOOLEAN;
-
- Output spaces into a file.
-
- Arguments:
- out : the file to write to.
- n : the number of spaces to write.
-
- Result:
- TRUE on success, else FALSE with out.status denoting the error.
-
- The output is linewrapped to 80 chars per line.
-
-
- PROCEDURE clear * (VAR out : File);
- PROCEDURE Clear * (VAR out : File) : BOOLEAN;
-
- Output a formfeed into a file.
-
- Arguments:
- out : the file to write to.
-
- Result:
- TRUE on success, else FALSE with out.status denoting the error.
-
-
- PROCEDURE format * (VAR out : File; VAR str: String; data:LONGINT);
- PROCEDURE Format * (VAR out : File; VAR str: String; data:LONGINT) : BOOLEAN;
-
- Output a single formatted item into a file.
-
- Arguments:
- out : the file to write to.
- str : the format string.
- data : the item to output.
-
- Result:
- TRUE on success, else FALSE with file.status denoting the error.
-
- %% => %
- links führ.0 min.max Breite longdata dez|hex|string|char
- % [-] [0] [123 [.123] ] [l] (d|x|s|c)
-
- Char is always WORD, even when specified as 'l'!
- String adresses are always LONG!
-
- Do NOT generate more than 255 chars.
-
-
- PROCEDURE writeInt * (VAR out: File; x: LONGINT; n: INTEGER);
- PROCEDURE WriteInt * (VAR out: File; x: LONGINT; n: INTEGER) : BOOLEAN;
-
- Output an integer into a file.
-
- Arguments:
- out : the file to write to.
- x : the integer to write.
- n : the minimal number of characters to write.
-
- Result:
- TRUE on success, else FALSE with out.status denoting the error.
-
- The integer will be leftadjusted.
-
-
- PROCEDURE writeHex * (VAR out : File; x: LONGINT; n: INTEGER);
- PROCEDURE WriteHex * (VAR out : File; x: LONGINT; n: INTEGER) : BOOLEAN;
-
- Output a hex integer into a file.
-
- Arguments:
- out : the file to write to.
- x : the integer to write.
- n : the minimal number of characters to write.
-
- Result:
- TRUE on success, else FALSE with out.status denoting the error.
-
- The integer will be leftadjusted and written in base-16 with leading zeroes.
-
-
- PROCEDURE read * (VAR in : File; VAR ch: CHAR);
- PROCEDURE Read * (VAR in : File; VAR ch: CHAR) : BOOLEAN;
-
- Read a character from a file.
-
- Arguments:
- in : the file to read from.
- ch : variable taking the character to read
-
- Result:
- TRUE on success, else FALSE with file.status denoting the error.
- ch: the character read.
-
-
- PROCEDURE readString * (VAR in : File; VAR str: ARRAY OF CHAR);
- PROCEDURE ReadString * (VAR in : File; VAR str: ARRAY OF CHAR) : BOOLEAN;
-
- Read a string from a file.
-
- Arguments:
- in : the file to read from.
- str : variable taking the string to read
-
- Result:
- TRUE on success, else FALSE with file.status denoting the error.
- str: the string read.
-
- The function reads until an \0 or \n is encountered (which won't be
- stored), or the buffer is exhausteDos. If possible, the string
- is terminated by \0.
-
-
- PROCEDURE readLong * (VAR in : File; VAR x: LONGINT);
- PROCEDURE ReadLong * (VAR in : File; VAR x: LONGINT): BOOLEAN;
-
- Read a long integer from a file.
-
- Arguments:
- in : the file to read from.
- x : variable taking the long integer read
-
- Result:
- TRUE on success, else FALSE with file.status denoting the error.
- If FALSE is returned, but in.status is 'ok', then the read characters
- do not form a legal number.
- x: the long integer read.
-
- Linebreaks after a number aren't read.
- Leading whitespace will be ignored.
-
-
- PROCEDURE readInt * (VAR in : File; VAR x: INTEGER);
- PROCEDURE ReadInt * (VAR in : File; VAR x: INTEGER): BOOLEAN;
-
- Read an integer from a file.
-
- Arguments:
- in : the file to read from.
- x : variable taking the integer read
-
- Result:
- TRUE on success, else FALSE with file.status denoting the error.
- If FALSE is returned, but in.status is 'ok', then the read characters
- do not form a legal number.
- x: the integer read.
-
- Linebreaks after a number aren't read.
- Leading whitespace will be ignored.
-
-
- PROCEDURE readShort * (VAR in : File; VAR x: SHORTINT);
- PROCEDURE ReadShort * (VAR in : File; VAR x: SHORTINT): BOOLEAN;
-
- Read a short integer from a file.
-
- Arguments:
- in : the file to read from.
- x : variable taking the short integer read
-
- Result:
- TRUE on success, else FALSE with file.status denoting the error.
- If FALSE is returned, but in.status is 'ok', then the read characters
- do not form a legal number.
- x: the short integer read.
-
- Linebreaks after a number aren't reaDos.
- Leading whitespace will be ignoreDos.
-
-
- PROCEDURE readHex * (VAR in : File; VAR x: LONGINT);
- PROCEDURE ReadHex * (VAR in : File; VAR x: LONGINT): BOOLEAN;
-
- Read a long integer in base-16 notation from a file.
-
- Arguments:
- in : the file to read from.
- x : variable taking the long integer read
-
- Result:
- TRUE on success, else FALSE with file.status denoting the error.
- If FALSE is returned, but in.status is 'ok', then the read characters
- do not form a legal number.
- x: the long integer read.
-
- Linebreaks after a number aren't reaDos.
- Leading whitespace will be ignoreDos.
-
- END fio.
-
- (***************************************************************************)
-
- (* $VER: fRealIO 1.1 (21-May-94) Copyright © by Lars Düning *)
-
- DEFINITION fRealIO;
-
- ---------------------------------------------------------------------------
- File-IO of REAL numbers for Amiga-Oberon.
-
- Copyright © 1991-1994 Lars Düning - All rights reserved.
- Permission granted for non-commercial use.
- ---------------------------------------------------------------------------
- CREDIT:
- This module evolved from RealIO of Amiga-Oberon v1.17.1
- ---------------------------------------------------------------------------
-
- PROCEDURE ParseReal * ( VAR in : fio.File; VAR str : ARRAY OF CHAR) : BOOLEAN;
-
- Parse a REAL number from a file.
-
- Arguments:
- in : the file to read from.
- str : buffer taking the number string.
-
- Result:
- TRUE on success, else FALSE with in.status denoting the error.
- If FALSE is returned, but in.status is 'ok', then no correct number
- could be read.
-
- Leading whitespace are ignored, trailing linebreaks are not read.
-
-
- PROCEDURE writeReal * ( VAR f : fio.File
- ; r : REAL
- ; v, n : INTEGER
- ; exp : BOOLEAN
- );
- PROCEDURE WriteReal * ( VAR f : fio.File
- ; r : REAL
- ; v, n : INTEGER
- ; exp : BOOLEAN
- ): BOOLEAN;
-
- Write a REAL number into a file.
-
- Arguments:
- f : the file to write to.
- r : the number to write.
- v : number of digits in front of the '.'
- n : number of digits after the '.'
- exp: if TRUE, the 'E' notation is used when appropriate.
-
- Result:
- TRUE on success, else FALSE with out.status denoting the error.
- If FALSE is returned, but out.status is 'ok', then the number is
- larger than the allowed number of digits.
-
-
- PROCEDURE readReal * (VAR f : fio.File; VAR r: REAL);
- PROCEDURE ReadReal * (VAR f : fio.File; VAR r: REAL): BOOLEAN;
-
- Read a REAL number from a file.
-
- Arguments:
- f : the file to read from.
- r : variable to take the number read.
-
- Result:
- TRUE on success, else FALSE with out.status denoting the error.
- If FALSE is returned, but out.status is 'ok', then no correct number
- could be read.
- r: the number read.
-
- END fRealIO.
-
- (***************************************************************************)
-
- (* $VER: fLRealIO 1.1 (21-May-94) Copyright © by Lars Düning *)
-
- DEFINITION fLRealIO;
-
- ---------------------------------------------------------------------------
- File-IO of LONGREAL numbers for Amiga-Oberon.
-
- Copyright © 1991-1994 Lars Düning - All rights reserved.
- Permission granted for non-commercial use.
- ---------------------------------------------------------------------------
- CREDIT:
- This module evolved from RealIO of Amiga-Oberon v1.17.1
- ---------------------------------------------------------------------------
-
- PROCEDURE writeReal * ( VAR f : fio.File
- ; r : LONGREAL
- ; v, n : INTEGER
- ; exp : BOOLEAN
- );
- PROCEDURE WriteReal * ( VAR f : fio.File
- ; r : LONGREAL
- ; v, n : INTEGER
- ; exp : BOOLEAN
- ): BOOLEAN;
-
- Write a REAL number into a file.
-
- Arguments:
- f : the file to write to.
- r : the number to write.
- v : number of digits in front of the '.'
- n : number of digits after the '.'
- exp: if TRUE, the 'E' notation is used when appropriate.
-
- Result:
- TRUE on success, else FALSE with out.status denoting the error.
- If FALSE is returned, but out.status is 'ok', then the number is
- larger than the allowed number of digits.
-
-
- PROCEDURE readReal * (VAR f : fio.File; VAR r: LONGREAL);
- PROCEDURE ReadReal * (VAR f : fio.File; VAR r: LONGREAL): BOOLEAN;
-
- Read a REAL number from a file.
-
- Arguments:
- f : the file to read from.
- r : variable to take the number read.
-
- Result:
- TRUE on success, else FALSE with out.status denoting the error.
- If FALSE is returned, but out.status is 'ok', then no correct number
- could be read.
- r: the number read.
-
- END fLRealIO.
-
-